import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './pointsdetails.scss'
import cat04 from '../../assets/kedouimg01/sckf.png'
import xl from '../../assets/kedouimg01/xl.png'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
		resdata:[],
		result:[],
		pageNumber:0,
		money:0,
		navindex:1,
		islisyr:0,
		createDateEnd:'',
		indexAssets:0,
		indexAssetsFormula:'',
		appmark:CommonJs.getmark(),
    }
  }
  config = {
    navigationBarTitleText: '加载中'
  }
  componentWillMount () {
	if(this.state.appmark=='xjzb'){
		Taro.setNavigationBarTitle({title:'价值资产'})
	}
	else{
		Taro.setNavigationBarTitle({title:'消费贡献'})
	}
	var money =this.$router.preload.money;
	var indexAssets =this.$router.preload.indexAssets;
	var indexAssetsFormula =this.$router.preload.indexAssetsFormula;
	this.setState({
		money:money,
		indexAssets:indexAssets,
		indexAssetsFormula:indexAssetsFormula,
	  })
	this.getalldate()
	this.getdate(0)
  }
  componentDidShow () {
  	
  }
  getalldate(){
	var _this = this;
	var url = '/crm/papi/v1.9/currency?assetType=XFGF'
	CommonJs.ajaxRequest(url,'','GET',function(res){
		if (res.data.length>0) {
			var resdata = _this.state.resdata
			resdata = res.data[0]
			  _this.setState({
				resdata: resdata,
			  })     
		  } 
		},"wfw")
}
  
  

  getdate(pageNumber){
	var _this=this
	if(_this.state.createDateEnd != ''){
		var url = '/crm/papi/v1.9/currency?assetType=XFGF'+ '&createDateEnd=' + _this.state.createDateEnd
	}else{
		var url = '/crm/papi/v1.9/currency?assetType=XFGF'
	}
	var dates={

	}
	var type=this.state.navindex;
	if(type==1){
		dates.inOrOut=true
	}
	else{
		dates.inOrOut=false
	}
	CommonJs.ajaxRequest(url,dates,'GET',function(res){
		if (res.data.length>0) {
		var results = _this.state.result
		var result = res.data[0].assetTypeDetailsList
		if(pageNumber==0){
			results=[]
		  }
		for(var i = 0; i < result.length; i++){
		  results.push(result[i]);
		}
		  _this.setState({
			result: results,
			pageNumber:1
		  })

	  } 
	},"wfw")
}

  changeMoney(val){
	  this.setState({
		  navindex:val,
		  result:[],
		  pageNumber:0
	  })
	  var _this=this;
	  setTimeout(function(){
		  _this.getdate(0)
	  },600)	

  }
  onDateChange(e){
	  var _this = this;
	var createDateEnd = _this.state.createDateEnd
	var evalue = e.detail.value
		createDateEnd =evalue
		_this.setState({
			result:[],
			createDateEnd:createDateEnd,
			islisyr:1
			  })
			  setTimeout(function(){
				_this.getdate(0)
			},600)
  }
  

  render () {
   const result = this.state.result
   const resdata = this.state.resdata
   const money = this.state.money
   const appmark = this.state.appmark
    return (
      <View className='page'>
		  <ScrollView className='wdt-list' scrollY='true' onScrollToLower={this.loadMore.bind(this,'')}>
       			<View className='wdt-tj'>

				   <View className='wdt-li' style={appmark=='xjzb'?'':'display:none'}>
					   <View className='wdt-top'>价值资产={this.state.indexAssetsFormula}</View>
					   <View className='wdt-tops'>价值资产:{this.state.indexAssets/100}</View>
						   <Text>消费工分</Text>
						   <View className='wdt-lis'>
							   <Picker mode='date' onChange={this.onDateChange.bind(this)} fields='month'>
                				<View className='picker'>{this.state.islisyr == 1 ?this.state.createDateEnd : '本月'}<Image className='xl' mode='widthFix' src={xl}></Image></View>
              				</Picker>
							   </View>
					   </View>

       				<View className='wdt-li' style={appmark=='xjzb'?'display:none':''}>
					   <View className='wdt-top'>消费贡献={this.state.indexAssetsFormula}</View>
					   <View className='wdt-tops'>消费贡献:{this.state.indexAssets/100}</View>
						   <Text>消费贡献</Text>
						   <View className='wdt-lis'>
							   <Picker mode='date' onChange={this.onDateChange.bind(this)} fields='month'>
                				<View className='picker'>{this.state.islisyr == 1 ?this.state.createDateEnd : '本月'}<Image className='xl' mode='widthFix' src={xl}></Image></View>
              				</Picker>
							   </View>
					   </View>
					<View className='wdt-li02'>{money/100}</View>
					<View className='wdt-li03'>
       					<Text className='wdt-r'>本月收入：{!resdata||resdata.length==0 ? '0':resdata.monthTotal.income/100}</Text>
       					<Text className='wdt-l'>本月支出：{!resdata||resdata.length==0 ? '0':resdata.monthTotal.expenditure/100}</Text>
       				</View>
       			</View>
       			<View className='wdt-mx'>
       				<View className='wdt-tit'>
       					<Text className={this.state.navindex==1?'tit-li activer':'tit-li'} onClick={this.changeMoney.bind(this,1)}>收入</Text>
       					<Text className={this.state.navindex==2?'tit-li activer':'tit-li'} onClick={this.changeMoney.bind(this,2)}>支出</Text>
       				</View>
       				
       				<View className='qun-mingxibo'>
					   <View className='nodate' style={!result||result.length==0?'':'display:none;'}>暂无数据</View>
						   {result.map((item,index)=>(
							   <View className='qun-mingxilist'>
							   <View className='qun-mngxicont'>
								 <View className='qun-mngxileft'>
						   			 <Text className='qun-minxizngs qun-reanao'>{item.note}</Text>
						  			 <Text className='qun-minxizngs qun-minxitit'>{CommonJs.FormatDate(item.createAt,3)}</Text>
								 </View>
								 <View className='qun-mngxiright'>
						  			<Text style="margin-top:0" className={this.state.navindex==1?'qun-minxizngs qun-minxijine':'qun-minxizngs qun-minxijine qun-colors'}>{item.changeAmount/100}</Text>
								 </View>
							   </View>
						   </View>
						   ))}

			        </View>
       			</View>
		   </ScrollView>
      </View>
    )
  }
}

 